from django.db import models
from django.contrib.auth.models import User

class AdminProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, verbose_name='用户')
    role = models.CharField(max_length=50, verbose_name='角色')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    
    class Meta:
        verbose_name = '管理员资料'
        verbose_name_plural = '管理员资料'
    
    def __str__(self):
        return f"{self.user.username} - {self.role}"

# 添加操作日志模型
class OperationLog(models.Model):
    user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, verbose_name='操作用户')
    operation = models.CharField(max_length=100, verbose_name='操作类型')
    model = models.CharField(max_length=100, verbose_name='操作模型')
    detail = models.TextField(verbose_name='操作详情')
    ip_address = models.GenericIPAddressField(verbose_name='IP地址')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='操作时间')
    
    class Meta:
        verbose_name = '操作日志'
        verbose_name_plural = '操作日志'
        ordering = ['-created_at']
    
    def __str__(self):
        return f"{self.user.username} - {self.operation} - {self.created_at}"